using Microsoft.EntityFrameworkCore;
using UniversalAdminSystem.Domian.Core.Interfaces;
using UniversalAdminSystem.Domian.SystemSettings.Aggregates;
using UniversalAdminSystem.Domian.SystemSettings.IRepository;
using UniversalAdminSystem.Infrastructure.Persistence.DbContexts;

namespace UniversalAdminSystem.Infrastructure.Persistence.Repositories;

public class SystemSettingRepository : BaseRepository<SystemSetting>, ISystemSettingRepository
{
    public SystemSettingRepository(UniversalAdminSystemDbContext context) : base(context)
    {
    }

    public async Task<SystemSetting?> GetByKeyAsync(string key)
    {
        return await _DbContext.Set<SystemSetting>()
            .FirstOrDefaultAsync(s => s.Key.Value == key);
    }

    public async Task<IEnumerable<SystemSetting>> GetByGroupAsync(string group)
    {
        return await _DbContext.Set<SystemSetting>()
            .Where(s => s.Key.Value.StartsWith(group))
            .ToListAsync();
    }
} 